Skip to content

feat: Charter-driven planning + fallback model selection with deterministic retry#13

Merged
Steake merged 4 commits into
mainfrom
copilot/update-repo-architect-workflow-again
Mar 13, 2026
Merged

feat: Charter-driven planning + fallback model selection with deterministic retry#13
Steake merged 4 commits into
mainfrom
copilot/update-repo-architect-workflow-again

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 13, 2026

Description

Two capabilities added to repo_architect.py and the repo-architect workflow:

1. Fallback GitHub Models selection with deterministic retry

workflow_dispatch exposes an explicit fallback model input; the Python layer enforces a narrow, deterministic fallback trigger set. The github_model input default remains '' so the catalog-based model resolution step remains the primary selection mechanism — an explicit value still overrides it.

Workflow (repo-architect.yml)

  • github_model default remains '' (catalog resolution is primary; explicit value overrides)
  • New github_fallback_model input, default openai/gpt-5
  • Both exported as GITHUB_MODEL / GITHUB_FALLBACK_MODEL env vars into the run step

Python (repo_architect.py)

  • _should_try_fallback(msg) — triggers on model unavailability and HTTP 403/404/429/5xx/timeout; bare strings without a status code (e.g. "rate limit exceeded") do not trigger
  • call_models_with_fallback_or_none uses _should_try_fallback; retries exactly once, then surfaces both errors combined
  • Config.github_fallback_model read from GITHUB_FALLBACK_MODEL
  • JSON output gains: primary_model, fallback_model, model_used, fallback_used, fallback_reason

2. Charter-driven planning

repo_architect.py now loads the canonical architectural charters and injects their guidance into every model call.

  • CHARTER_PATHS — canonical tuple of both charter relative paths
  • load_charter_context(git_root) — reads both files if present (silent on missing), SHA-256 hashes combined content
  • _charter_system_prefix(analysis) — prepends truncated charter text to model system messages (empty when no charter)
  • All model-calling plan builders (build_parse_errors_plan, build_import_cycles_plan, build_entrypoint_consolidation_plan, enrich_with_github_models) now receive charter guidance
  • JSON output gains top-level "charter" key: {loaded_files, content_hash, applied}
# Charter metadata shape in run_cycle / run_campaign result
{
  "charter": {
    "loaded_files": ["docs/architecture/GODELOS_ARCHITECTURAL_CHARTER.md",
                     "docs/architecture/GODELOS_REPO_IMPLEMENTATION_CHARTER.md"],
    "content_hash": "a3f9b2c1d4e5f678",
    "applied": true   # True when model was invoked with charter in context
  }
}

Related Issues

Test Evidence

======================== 88 passed, 1 warning in 1.01s =========================
  • 79 pre-existing tests all pass
  • 9 new TestCharterContext tests: no-files tolerance, partial load, both files, run_cycle/run_campaign metadata schema, _charter_system_prefix behavior, hash stability
  • 19 new TestShouldTryFallback / TestCallModelsWithFallback tests for fallback trigger set
  • CodeQL: 0 alerts

Checklist

  • Tests pass locally (pytest tests/)
  • Code is formatted (black . and isort .)
  • Documentation updated (if applicable)
  • No secrets or credentials committed
  • Related issue linked above
Original prompt

Update the repo-architect workflow and repo_architect.py in BraveNewCapital/GodelOS_StrangeDevLoop to support explicit primary/fallback GitHub Models selection with deterministic retry behavior and test coverage.

Repository: BraveNewCapital/GodelOS_StrangeDevLoop

Relevant existing files:

  • .github/workflows/repo-architect.yml
  • repo_architect.py

Current workflow details observed:

  • .github/workflows/repo-architect.yml already has a workflow_dispatch input named github_model, but it currently defaults to an empty string.
  • The workflow currently resolves REPO_ARCHITECT_PREFERRED_MODEL and REPO_ARCHITECT_FALLBACK_MODEL in a dedicated step and passes --github-model when the workflow input is set.
  • The workflow does not currently expose GITHUB_MODEL and GITHUB_FALLBACK_MODEL as explicit environment variables for the run step.

Current Python details observed:

  • repo_architect.py already has DEFAULT_PREFERRED_MODEL = "anthropic/claude-sonnet-4.6" and DEFAULT_FALLBACK_MODEL = "google/gemini-3-pro".
  • It already has fallback-oriented helpers such as _is_model_unavailable_error() and call_models_with_fallback_or_none(), but the retry behavior is too narrow for the requested cases and the output metadata does not match the requested schema.
  • build_config() currently reads GITHUB_MODEL into github_model, while preferred/fallback model values are primarily sourced from REPO_ARCHITECT_PREFERRED_MODEL and REPO_ARCHITECT_FALLBACK_MODEL.

Requested changes:

  1. In .github/workflows/repo-architect.yml, add a new workflow_dispatch input:

    • github_model: default to the Claude Sonnet 4.5 model id.
    • github_fallback_model: default to the GPT-5 model id.
  2. Export both as environment variables in the workflow run context:

    • GITHUB_MODEL
    • GITHUB_FALLBACK_MODEL
  3. In repo_architect.py:

    • Attempt GitHub Models inference using GITHUB_MODEL first.
    • If inference fails due to unsupported model, permission issue, HTTP 403, 404, 429, timeout, or 5xx provider failure, retry exactly once with GITHUB_FALLBACK_MODEL.
    • Keep the retry logic narrow and deterministic.
    • If the fallback also fails, surface both errors together, preserving the original primary error and the fallback error.
  4. Add metadata to the JSON output:

    • primary_model
    • fallback_model
    • model_used
    • fallback_used (true/false)
    • fallback_reason
  5. Add tests covering:

    • primary success
    • primary failure and fallback success
    • primary failure and fallback failure
  6. Do not change unrelated workflow behavior.

  7. Open a PR.

Implementation guidance:

  • Keep backward compatibility where practical, but prioritize the requested environment-variable-driven behavior.
  • Ensure the fallback trigger set is explicit and minimal: unsupported model / model unavailable conditions, permission issues, 403, 404, 429, timeout, and 5xx/provider failures.
  • Make the combined error reporting deterministic and easy to assert in tests.
  • Update any workflow-generation logic in repo_architect.py as needed so generated workflow YAML stays aligned with the checked-in workflow.
  • If tests already exist for this area, extend them; otherwise add focused new tests in the repository’s existing Python test layout.
  • Create a pull request with the completed changes.

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: Update the repo-architect workflow and repo_architect.py to support a primary model and a fallback model.

Requirements:

  1. In .github/workflows/repo-architect.yml add a new workflow_dispatch input:

    • github_model: default to Claude Sonnet 4.5 model id
    • github_fallback_model: default to GPT-5 model id
  2. Export both as environment variables:

    • GITHUB_MODEL
    • GITHUB_FALLBACK_MODEL
  3. In repo_architect.py:

    • attempt model inference using GITHUB_MODEL first
    • if inference fails due to unsupported model, permission issue, 403, 404, 429, timeout, or 5xx provider failure, retry once with GITHUB_FALLBACK_MODEL
    • keep the retry narrow and deterministic
    • if fallback also fails, surface the original primary error plus fallback error
  4. Add metadata to the JSON output:

    • primary_model
    • fallback_model
    • model_used
    • fallback_used: true/false
    • fallback_reason
  5. Add tests for:

    • primary success
    • primary failure and fallback success
    • primary failure and fallback failure
  6. Do not change unrelated workflow behavior.

  7. Open a PR.

Assistant: I’m waiting on your approval of the requested repository change so I can continue and open the PR.

This pull request was created from Copilot chat.


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

… retry and metadata

- Add github_fallback_model dispatch input (default: openai/gpt-5) to workflow
- Update github_model dispatch input default to anthropic/claude-sonnet-4.5
- Export GITHUB_MODEL and GITHUB_FALLBACK_MODEL as env vars in run step
- Add _should_try_fallback() covering 403/404/429/5xx/timeout/model-unavailable
- Update call_models_with_fallback_or_none to use _should_try_fallback
- Add github_fallback_model to Config, read from GITHUB_FALLBACK_MODEL env var
- Add primary_model/fallback_model/model_used/fallback_used to JSON output
- Sync workflow_yaml() to match checked-in workflow YAML
- Add 19 new tests: TestShouldTryFallback, extended fallback/metadata coverage

Co-authored-by: Steake <530040+Steake@users.noreply.github.com>
Copilot AI changed the title [WIP] Update repo-architect workflow and Python script for GitHub model selection feat: Primary/fallback GitHub Models selection with deterministic retry and output metadata Mar 13, 2026
Copilot AI requested a review from Steake March 13, 2026 07:41
- Add CHARTER_PATHS constant and _MAX_CHARTER_CHARS_PER_FILE limit
- Add load_charter_context() to load both charter files tolerantly
- Add _charter_system_prefix() helper for model system messages
- Inject charter guidance into enrich_with_github_models (report mode)
- Inject charter guidance into build_parse_errors_plan, build_import_cycles_plan,
  build_entrypoint_consolidation_plan (mutate mode)
- Include charter metadata (loaded_files, content_hash, applied) in
  run_cycle and run_campaign JSON output under top-level "charter" key
- Add TestCharterContext (9 tests: missing files, partial, full ingestion,
  metadata in run_cycle/run_campaign, system prefix helpers, hash stability)
- Update REQUIRED_OUTPUT_FIELDS and campaign contract to include "charter"

Co-authored-by: Steake <530040+Steake@users.noreply.github.com>
Copilot AI changed the title feat: Primary/fallback GitHub Models selection with deterministic retry and output metadata feat: Charter-driven planning + primary/fallback model selection with deterministic retry Mar 13, 2026
@Steake Steake marked this pull request as ready for review March 13, 2026 07:57
Copilot AI review requested due to automatic review settings March 13, 2026 07:57
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 13, 2026

🧪 CI — Python 3.10

�[31mERROR�[0m tests/test_cognitive_subsystem_activation.py::�[1mTestEndToEndFlow::test_context_engine_round_trip�[0m - ModuleNotFoundError: No module named 'requests'
�[31mERROR�[0m tests/test_cognitive_subsystem_activation.py::�[1mTestEndToEndFlow::test_nlg_pipeline_process�[0m - ModuleNotFoundError: No module named 'requests'
�[31m===== �[31m�[1m4 failed�[0m, �[32m1103 passed�[0m, �[33m81 skipped�[0m, �[33m65 warnings�[0m, �[31m�[1m22 errors�[0m�[31m in 37.84s�[0m�[31m ======�[0m

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 13, 2026

🧪 CI — Python 3.11

�[31mERROR�[0m tests/test_cognitive_subsystem_activation.py::�[1mTestEndToEndFlow::test_context_engine_round_trip�[0m - ModuleNotFoundError: No module named 'requests'
�[31mERROR�[0m tests/test_cognitive_subsystem_activation.py::�[1mTestEndToEndFlow::test_nlg_pipeline_process�[0m - ModuleNotFoundError: No module named 'requests'
�[31m===== �[31m�[1m4 failed�[0m, �[32m1103 passed�[0m, �[33m81 skipped�[0m, �[33m65 warnings�[0m, �[31m�[1m22 errors�[0m�[31m in 39.95s�[0m�[31m ======�[0m

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds charter-driven planning and primary/fallback model selection with deterministic retry to repo_architect.py and the repo-architect workflow.

Changes:

  • Expanded fallback trigger set (_should_try_fallback) to cover HTTP 403/404/429/5xx and timeout errors, with new github_fallback_model Config field and enriched JSON output metadata
  • Charter context loading (load_charter_context, _charter_system_prefix) that injects architectural charter guidance into all model calls, with metadata in run_cycle/run_campaign output
  • Workflow updated with new github_fallback_model input and GITHUB_MODEL/GITHUB_FALLBACK_MODEL env vars

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
.github/workflows/repo-architect.yml Added github_fallback_model input, changed github_model default, exported both as env vars
repo_architect.py Added _should_try_fallback, load_charter_context, _charter_system_prefix, charter injection in model calls, new metadata fields
tests/test_repo_architect.py Added TestShouldTryFallback (11 tests), extended TestCallModelsWithFallback (6 tests), added TestCharterContext (9 tests), updated output schema assertions

Comment thread .github/workflows/repo-architect.yml Outdated
description: 'GitHub Models model id (overrides preferred model)'
required: false
default: ''
default: 'anthropic/claude-sonnet-4.5'
@Steake
Copy link
Copy Markdown

Steake commented Mar 13, 2026

@copilot apply changes based on the comments in this thread

…log resolution

Co-authored-by: Steake <530040+Steake@users.noreply.github.com>
Copy link
Copy Markdown
Author

Copilot AI commented Mar 13, 2026

@copilot apply changes based on the comments in this thread

Fixed in 6f48bc8. Reverted github_model default back to '' so the "Resolve GitHub Models configuration" catalog step remains the primary model selection mechanism. An explicit user-provided value still overrides via --github-model as before.

Copilot AI changed the title feat: Charter-driven planning + primary/fallback model selection with deterministic retry feat: Charter-driven planning + fallback model selection with deterministic retry Mar 13, 2026
@Steake Steake merged commit b5f68a8 into main Mar 13, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants